/* 
 * File:   BlockGroup.h
 * Author: chris
 *
 * Created on January 26, 2009, 8:26 PM
 */

#ifndef _BLOCKGROUP_H
#define	_BLOCKGROUP_H

/*
 * Created on February 2, 2008.
 *
 * Modifed: CGP; 1/26/09; Converted from Java to C++.
 */


/**
 * This class represents a BlockLinkedList obtained from a FreeList.
 *
 * @author Christopher G. Prince
 */
class BlockGroup : public BlockLinkedList {

public:
    /** Initializes a new BlockGroup.
     *
     * @param bll BlockLinkedList to use to initialize. Does not modify disk.
     */
	BlockGroup(BlockLinkedList *bll);

    /** Enables you to re-open a BlockGroup. Assumes that the BlockGroup is not
     * currently open. This enables you to re-open a BlockGroup on subsequent runs of testing
     * programs, after an initial run when a BlockGroup was created but not deallocated.
	 * Doesn't modify the Disk.
     *
     * Only basic sanity checking is done on the parameters (e.g., range checking).
     *
     * @param startBlock is the starting block number of the BlockGroup.
     * @param endBlock is the ending block number of the BlockGroup.
     * @param numberOfBlocks is the number of blocks in this BlockGroup.
     * @param motherFreeList is the BlockGroup's originating Free List.
     *
     * @throws BlockGroupException when a parameter is out of range.
     */
    BlockGroup(unsigned int startBlock, unsigned int endBlock, 
            unsigned int numberOfBlocks, BlockLinkedList *motherFreeList);

    /** Add another (empty) block to the end of this BlockGroup, from the Free List.
     * You need to make sure the FreeList has blocks left in it before calling this method.
     *
     * @return true iff FSBlock could be added (i.e., if the FreeList has a block left).
     */
    bool AddBlock();

    /** Add another block to the end of this BlockGroup, from the Free List.
     * You need to make sure the FreeList has blocks left in it before calling this method.
     *
     * Note that the block number for the FSBlock parameter new_block WILL be over written.
     * It is set to some value from the FreeList.
     * @param new_block The new FSBlock we want to add.
     * @return true iff FSBlock could be added (i.e., if the FreeList has a block left).
     */
    bool AddBlock(FSBlock *new_block);
	
	/** Sets the free list for this BlockGroup.
	 */
	void SetFreeList(BlockLinkedList *motherFreeList);

    /** Data members
     */
protected:
    friend class FreeList;

    /** This is actually the FreeList. I've used the superclass
     * BlockLinkedList to get around referencing problems.
     */
    BlockLinkedList *m_motherFreeList; 
};


#endif	/* _BLOCKGROUP_H */

